import styled from 'styled-components';
import Icon from '../../component/Icon';

interface Props {
    icon?: { image?: string, background?: string };
    title: string;
    sub: string;
    tips?: string;
    className?: string
}

const Container = styled.div`
    border-radius: 1rem;
    display: flex;
    padding: 1rem;
    box-sizing: border-box;
    flex-direction: column;
    width: 100%;
    position: relative;
`

const Top = styled.div`
    display: flex;
    align-items: center;
    justify-content: start;
`

const IconBox = styled(Icon) <{ $bgColor?: string }>`
    width: 1.375rem;
    height: 1.375rem;
    background-color: ${({ $bgColor }) => $bgColor};
    border-radius: 1.25rem;
    margin-right: .5rem;
`

const Bottom = styled.div`
    flex: 1;
    display: flex;
    align-items: center;
;
`

const Tips = styled.div`
    position: absolute;
    bottom: 0.125rem;
    left: 50%;
    transform: translate(-50%, 0);
    font-size: .625rem;
    color: #ffffffc0;
    width: 100%;
    
`

const Title = styled.span`
    font-size: 1rem;
    font-weight: 400;
    color: rgba(0,0,0,0.8);
    line-height: 1.375rem;
`

const Count = styled.span`
    font-size: 1.25rem;
    font-weight: 500;
    color: rgba(0,0,0,0.8);
    line-height: 1.75rem;
    flex: 1;
    text-align: start;
`

const Item: React.FC<Props> = ({ title, sub, icon, className, tips }) => {
    return <Container className={className}>
        <Top>
            {icon && <IconBox
                src={icon?.image}
                $bgColor={icon?.background}
            />}
            <Title>{title}</Title>
        </Top>
        <Bottom>
            {icon && <IconBox />}
            <Count>{sub}</Count>
            <Tips>{tips}</Tips>
        </Bottom>
    </Container>
}

export default Item